package com.qst.crop.service.impl;

import com.qst.crop.dao.CommentDao;
import com.qst.crop.entity.Comment;
import com.qst.crop.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService{
    @Autowired
    private CommentDao commentDao;

    private final JdbcTemplate jdbcTemplate;
    public CommentServiceImpl(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public void add(Comment comment) {
        commentDao.insertSelective(comment);
    }

    @Override
    public List<Comment> selectByOrderId(Integer orderId) {
        List<Comment> comments = commentDao.selectByOrderId(orderId);
        return comments;
    }

    @Override
    public List<Comment> selectAllComments() {
        String sql = "SELECT * FROM tb_comment";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Comment.class));
    }
}
